package com.slkj.shilixiaoyuanapp.ui.user.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.TextureView;
import android.widget.EditText;
import android.widget.TextView;

import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.base.ActivityInfo;
import com.slkj.shilixiaoyuanapp.base.BaseActivity;
import com.slkj.shilixiaoyuanapp.net.CommonResult;
import com.slkj.shilixiaoyuanapp.net.HttpHeper;
import com.slkj.shilixiaoyuanapp.net.callback.CommonCallBack;
import com.slkj.shilixiaoyuanapp.view.dialog.LoadSuccessAndFailDialog;
import com.tkk.api.RxEventProcessor;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.functions.Consumer;

import static com.slkj.shilixiaoyuanapp.entity.code.RxEventProcessorTag.CHANGE_NIKENAME_FINSH;

/**
 * 修改用户昵称
 */
@ActivityInfo(layout = R.layout.activity_change_nick_name, title = "更改名字", rightHint = "保存")
public class ChangeNickNameActivity extends BaseActivity {
    @BindView(R.id.edit)
    EditText edit;

    @Override
    protected void init() {

    }

    @Override
    protected void onRightTitleClick() {
        String name = edit.getText().toString();
        if (TextUtils.isEmpty(name)){
            return;
        }
        HttpHeper.get().userService().updateNikeName(name).compose(getThread())
                .compose(bindToLifecycle())
                .subscribe(new CommonCallBack<String>(true,ChangeNickNameActivity.this) {
                    @Override
                    public void onCallBackSuccess(String data) {
                        finish();
                        RxEventProcessor.get().post(CHANGE_NIKENAME_FINSH,name);
                        LoadSuccessAndFailDialog.showSuccess(ChangeNickNameActivity.this,data);
                    }
                });

    }


}
